/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mti.javashare.beans;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Sinheldrin
 */
@Entity
@Table(name = "user")
@XmlRootElement(name = "user")
public class User implements Serializable
{
    private int id;
    @Column(name="id")
    @Id
    @GeneratedValue
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    
    private String username;
    @Column(name="username")
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }
    
    private byte[] password;
    @Column(name="password")
    public byte[] getPassword() { return password; }
    public void setPassword(byte[] password) { this.password = password; }
    
    private Collection<File> files;
    @OneToMany(mappedBy="user")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Collection<File> getFiles() { return files; }
    public void setFiles(Collection<File> files) { this.files = files; }
    
    private Collection<User> friends;
    @ManyToMany
    @JoinTable(name = "friend",
        joinColumns = { @JoinColumn(name="iduser1") },
        inverseJoinColumns = { @JoinColumn(name="iduser2") }
    )
    @LazyCollection(LazyCollectionOption.FALSE)
    @XmlTransient
    public Collection<User> getFriends() { return this.friends; }
    public void setFriends(Collection<User> friends) { this.friends = friends; }
}
